<template>
  <my-simple-page
    :tableTitle="tableTitle"
    :search-fields="searchFields"
    :columns="columns"
    :edit-fields="editFields"
    :search-url="searchUrl"
    :save-url="saveUrl"
    :delete-url="deleteUrl">
  </my-simple-page>
</template>

<script>
  export default {
    name: "menu-index",
    data(){
      return{
        searchFields: [
          {
            type: 'input',
            label: '名称',
            prop: 'name'
          },{
            type: 'select',
            label: '状态',
            prop: 'status',
            dict: 'COMMON_STATUS_DICT'
          }
        ],
        tableTitle: '角色列表',
        columns: [
          {label:'名称',prop: 'name'},
          {label:'编码',prop: 'code'},
          {label:'状态',prop: 'status',render: this.renderStatus},
          {label:'说明',prop: 'roleDesc'}],
        editFields: [
          {
            type: 'input',
            label: '名称',
            prop: 'name',
            rules:{ required: true, message: '名称不能为空', trigger: 'blur' }
          },
          {
            type: 'input',
            label: '编码',
            prop: 'code',
            rules:{ required: true, message: '编码不能为空', trigger: 'blur' }
          },
          {
            type: 'textarea',
            label: '说明',
            prop: 'roleDesc'
          },
          {
            type: 'switch',
            label: '状态',
            prop: 'status'
          },
          {
            type: 'tree',
            label: '权限',
            prop: 'permission',
            url: '/api/sys-config/menu/getMenuTree'
          }
        ],
        searchUrl: '/api/sys-config/role/getRoleList',
        saveUrl: '/api/sys-config/role/saveRole',
        deleteUrl: '/api/sys-config/role/deleteRole',
      }
    },
    methods:{
      renderStatus(val){
        for(let item of this.statusDict){
          if (item.value == val){
            return item.label;
          }
        }
      },
    },
    created(){
      this.$ajax.getDict('COMMON_STATUS_DICT').then(res=>{
        this.statusDict = res;
      });
    }
  }
</script>

<style lang="scss" scoped>

</style>
